//
//  SWLoginReq.swift
//  BaseDemo
//
//  Created by linhan on 16/2/25.
//  Copyright © 2016年 me. All rights reserved.
//

import Foundation
class SWLoginReq: SWBaseRequest
{
    var phone:String = ""
    var password:String = ""
    var requestKey:String = ""
    
    override init()
    {
        super.init()
        options.authorize = false
        api = SWRequestAPI.Login
    }
    
    override var params:Any?
    {
        var param:[String:Any] = [:]
        param["phone"] = phone
        param["pwd"] = password
        return param
    }
    
    override func JSONToModel(_ json:JSON, JSONString:String, JSONData:Data) -> AnyObject?
    {
        return Mapper<SWLoginRsp>().map(JSONString: JSONString)
    }
    
}

enum SWAccountAuthStatus:Int
{
    case Success = 1
    case UnbindingMobile = 2
}

class SWLoginRsp: NSObject,Mappable
{
    var code:String?
    var data:SWAuthDataRsp?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        code    <- map["Statu"]
        data    <- map["BaseModle"]
    }
}

class SWAuthDataRsp: NSObject,Mappable
{
    var uid:Int?
    var haveBabyInfo:Int?
    var avatar:String?
    var identity:String?
    var mobile:String?
    var screenName:String?
    var desc:String?
    var token:String?
    var ssoTempticket:String?
    var status:Int?
    var child:SWChildRsp?
    var birthday:Date?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        let formatter:DateFormatter = DateFormatter()
        formatter.dateFormat = "YYYY-MM-dd"
        uid             <- map["userId"]
        token           <- map["ticket"]
        haveBabyInfo    <- map["haveBabyInfo"]
        avatar          <- map["headImg"]
        identity        <- map["identity"]
        mobile          <- map["mobilePhone"]
        screenName      <- map["nickName"]
        desc            <- map["sign"]
        ssoTempticket   <- map["register_token"]
        status          <- map["status"]
        child           <- map["babyInfo"]
        birthday       <- (map["birthday"], DateFormatterTransform(dateFormatter: formatter))
    }
}


